package com.mapeditor.toolbar {
	import AS3Events.AS3EventMessage;
	import AS3Events.AS3EventRouter;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Toolbar extends Sprite{
		
		private var buttons:Array;
		private var h:Number;
		
		/**
		 * construtor padrao da classe
		 */
		
		public function Toolbar()
		{
			this.buttons = new Array();	
			this.mouseChildren = true;
			this.mouseEnabled = true;
			this.h = 116;
			
		}
		
		public function addButtonImg(btnPath:String, w:Number=19,h:Number=23,nm:String=""):void{
			var i:uint = this.buttons.length;
			
			this.buttons[i]= new SmallButton(w,h);
			this.buttons[i].setContentImg(btnPath, w, h);
			this.buttons[i].name = nm;
		}
		
		
		public function outPut():void {
			var px:uint = 10;
			var py:uint = 2;
			var margin:uint = 5
			for each(var btn:SmallButton in this.buttons)			
			{
				addChild(btn);
				btn.x = px;
				btn.y = py;
				px += btn.width + margin; 
				btn.addEventListener(MouseEvent.MOUSE_OVER, _btnOver);	
				btn.addEventListener(MouseEvent.CLICK, _mouseUpBtn);	
			}
		}
		
		/**
		 * Evento de mouse over sobre um item do menu
		 * Adiciona o submenu
		 * @param	e
		 */
		private function _btnOver(e:MouseEvent):void {
			e.target.mouseOver();
			e.target.addEventListener(MouseEvent.MOUSE_OUT, _btnOut);				
		}
		private function _btnOut(e:MouseEvent):void {
			e.target.mouseOut();			
			e.target.removeEventListener(MouseEvent.MOUSE_OUT, _btnOut);
		}
		
		
		/**
		 * Evento de mouse up. Evento para criar um item.
		 * @param	e
		 */
		private function _mouseUpBtn(e:MouseEvent):void {
            
			var m:AS3EventMessage = AS3EventMessage.CreateMessage("event_btn", "ok", e.target.name);
		    AS3EventRouter.SendEvent("class_toolbar",m);
		    
		}//end of method
		
		
	}
}